<script lang="ts">
	import * as commands from '$lib/commands' // This should point to the file we export from Rust
	import { type Market } from '$lib/bindings/Market'
	import type {
		GetParams,
		IpcResponse,
		ListParams,
		Security,
		SecurityFilter,
		TradeBotFilter,
		TradeStrategy,
		TradeStrategyFilter,
	} from './bindings'
	import type { KlineFlat } from './bindings/KlineFlat'
	import type { Table } from './bindings/Table'

	let name = 'Conan'
	let greetMsg = ''

	let sh: Market = 'SH'

	async function greet() {
		greetMsg = await commands.greet(name + '.' + sh)
		// Define the argument
		let args1: ListParams<SecurityFilter> = {
			page: 0,
			size: 10,
			filter: null,
		}

		// const greet3 = await commands.greet3(args)
		// console.log('greet3 ', greet3)

		// const table: IpcResponse<Table> = await commands.get_kline_flat_table()

		// console.log('get_kline_flat_table ', table)

		// const list_securities: IpcResponse<Security[]> = await commands.list_securities(args1)
		// console.log('list_securities ', list_securities)
		// console.log('list_securities.0.id ', list_securities.result?.data[0].id?.id.)

		// // Define the argument
		// let args2: ListParams<SecurityFilter> = {
		// 	page: 0,
		// 	size: 10,
		// 	filter: { id: 'SZ.KZZ.128136', klt: 'M005', name: null },
		// }
		// const list_kline_flats: IpcResponse<KlineFlat[]> = await commands.list_kline_flats(args2)
		// console.log('list_kline_flats ', list_kline_flats)

		// let args: ListParams<TradeStrategyFilter> = {
		// 	page: 0,
		// 	size: 10,
		// 	filter: { id: null, klt: 'DAY' },
		// }

		// const rs: IpcResponse<TradeStrategy[]> = await commands.list_trade_strategies(args)
		// console.log('list_trade_strategies ', rs)

		// let args: ListParams<TradeBotFilter> = {
		// 	page: 0,
		// 	size: 10,
		// 	filter: { id: null, security_id: null, strategy_id: null },
		// }

		// const rs: IpcResponse<TradeBot[]> = await commands.list_trade_bots(args)
		// console.log('list_trade_bots ', rs)

		let args: GetParams = { id: 'j9tpv2dyh3op2jwgr107' }
		const rs = await commands.get_trade_bot(args)
		console.log('get_trade_bot ', rs)
	}
</script>

<div>
	<input id="greet-input" placeholder="Enter a name..." bind:value={name} />
	<button on:click={greet} class="text-3xl">Greet</button>
	<p>{greetMsg}</p>
</div>
